//
//  aboutUsViewController.m
//  ioschishan
//
//  Created by 千翼网络科技 on 2017/7/15.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "aboutUsViewController.h"
#import "getTermsOfServiceViewController.h"

@interface aboutUsViewController ()

@property (nonatomic,strong) NSMutableDictionary *dataDic;
@property (nonatomic,strong) UILabel *numberLabel;
@property (nonatomic,strong) UILabel *emailNumberLabel;

@end

@implementation aboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self requestData];
}

#pragma mark ----------------------- requestData ---------------------

- (void)requestData{
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication]keyWindow] animated:YES];
    hud.tag = 500;
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    
    NSMutableDictionary *productParams = [[NSMutableDictionary alloc]init];
    [productParams setValue: [PublicFunction getConfigWithKey:@"token"] forKey:@"token"];
    
    [[MNetworkHandler sharedInstance]conURL:more_aboutUs
                                networkType:NetWorkPOST
                                     params:productParams
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   
                                   if ([[returnData objectForKey:@"code"]intValue] == 1) {
                                       
                                       [hud removeFromSuperview];
                                       
                                       _dataDic = returnData[@"data"];
                                       NSLog(@"\n\n\n===关于我们===\n\n\n%@",_dataDic);
                                       [self reloadView];
                                       
                                   }else{
                                       
                                       [hud removeFromSuperview];
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:1.0f];
                                   }
                                   
                               } failureBlock:^(NSError *error) {
                                   
                                   [hud removeFromSuperview];
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:1.0f];
                               }];
}

- (void)reloadView{

    _numberLabel.text = _dataDic[@"phone"];
    _emailNumberLabel.text = _dataDic[@"email"];
    
}

#pragma mark ------------------ init -------------------

- (void)initView{
    
    self.title = @"关于我们";
    UIView *threadView = [[UIView alloc]initWithFrame:CGRectMake(0, screenScale(1), scrWidth(), screenScale(0.7))];
    threadView.backgroundColor = getColor(@"cccccc");
    [self.view addSubview:threadView];
    
    UIImageView *logoImg = [[UIImageView alloc]initWithFrame:CGRectMake(screenScale(138), screenScale(42), screenScale(120), screenScale(131))];
    logoImg.image = [UIImage imageNamed:@"logo1"];
    [self.view addSubview:logoImg];
    
    ///
    
    UIButton *phoneBtn = [ConfigXp buttonWithFrame:CGRectMake(0, screenScale(223), scrWidth(), screenScale(49))
                                              title:nil
                                         titleColor:nil
                                               font:nil
                                    backgroundColor:nil
                                              image:nil];
    phoneBtn.backgroundColor = getColor(@"ffffff");
    [phoneBtn addTarget:self action:@selector(forgetBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:phoneBtn];
    
    UIView *thread = [[UIView alloc]initWithFrame:CGRectMake(screenScale(15), screenScale(223), scrWidth() - screenScale(15), screenScale(0.5))];
    thread.backgroundColor = getColor(@"eeeeee");
    [self.view addSubview:thread];
    
    UILabel *phoneLabel = [ConfigXp labelWithFrame:CGRectZero
                                              text:@"客服电话"
                                         textColor:getColor(@"4a4a4a")
                                              font:get4sFont(13)
                                     textAlignment:NSTextAlignmentLeft
                                   backgroundColor:[UIColor clearColor]];
    [phoneBtn addSubview:phoneLabel];
    [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(thread.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        
        make.height.mas_equalTo(screenScale(49));
    }];
    
    _numberLabel = [ConfigXp labelWithFrame:CGRectZero
                                              text:@"18624045751"
                                         textColor:getColor(@"9b9b9b")
                                              font:get4sFont(12)
                                     textAlignment:NSTextAlignmentLeft
                                   backgroundColor:[UIColor clearColor]];
    [phoneBtn addSubview:_numberLabel];
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(thread.mas_bottom).with.offset(0);
        
        make.right.mas_equalTo(self.view).with.offset(screenScale(-30));
        make.height.mas_equalTo(screenScale(49));
    }];
    
    UIImageView *phoneImg = [[UIImageView alloc]init];
    phoneImg.image = [UIImage imageNamed:@"arrow_icon"];
    [phoneBtn addSubview:phoneImg];
    [phoneImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(phoneBtn.mas_centerY);
        make.right.mas_equalTo(self.view).with.offset(screenScale(-15));
        
        
    }];
    
    UIView *thread2 = [[UIView alloc]init];
    thread2.backgroundColor = getColor(@"eeeeee");
    [self.view addSubview:thread2];
    [thread2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(phoneLabel.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        make.right.mas_equalTo(self.view).with.offset(0);
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    ///
    
    UIButton *emailBtn = [ConfigXp buttonWithFrame:CGRectMake(0, screenScale(223), scrWidth(), screenScale(49))
                                             title:nil
                                        titleColor:nil
                                              font:nil
                                   backgroundColor:nil
                                             image:nil];
    emailBtn.backgroundColor = getColor(@"ffffff");
    [emailBtn addTarget:self action:@selector(emailBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:emailBtn];
    [emailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(thread2.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(0);
        make.right.mas_equalTo(self.view).with.offset(0);
        make.height.mas_equalTo(screenScale(49));
    }];
    
    UILabel *emailLabel = [ConfigXp labelWithFrame:CGRectZero
                                              text:@"客服邮箱"
                                         textColor:getColor(@"4a4a4a")
                                              font:get4sFont(13)
                                     textAlignment:NSTextAlignmentLeft
                                   backgroundColor:[UIColor clearColor]];
    [emailBtn addSubview:emailLabel];
    [emailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(thread2.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        
        make.height.mas_equalTo(screenScale(49));
    }];
    
    _emailNumberLabel = [ConfigXp labelWithFrame:CGRectZero
                                       text:@"83765087@qq.com"
                                  textColor:getColor(@"9b9b9b")
                                       font:get4sFont(12)
                              textAlignment:NSTextAlignmentLeft
                            backgroundColor:[UIColor clearColor]];
    [self.view addSubview:_emailNumberLabel];
    [_emailNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(thread2.mas_bottom).with.offset(0);
        
        make.right.mas_equalTo(self.view).with.offset(screenScale(-30));
        make.height.mas_equalTo(screenScale(49));
    }];
    
    UIImageView *emailImg = [[UIImageView alloc]init];
    emailImg.image = [UIImage imageNamed:@"arrow_icon"];
    [self.view addSubview:emailImg];
    [emailImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(emailBtn.mas_centerY);
        
        make.right.mas_equalTo(self.view).with.offset(screenScale(-15));
        
    }];
    
    UIView *emailThread1 = [[UIView alloc]init];
    emailThread1.backgroundColor = getColor(@"eeeeee");
    [self.view addSubview:emailThread1];
    [emailThread1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_emailNumberLabel.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        make.right.mas_equalTo(self.view).with.offset(0);
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    ///
    
    UIButton *termsBtn = [ConfigXp buttonWithFrame:CGRectMake(0, screenScale(223), scrWidth(), screenScale(49))
                                             title:nil
                                        titleColor:nil
                                              font:nil
                                   backgroundColor:nil
                                             image:nil];
    termsBtn.backgroundColor = getColor(@"ffffff");
    [termsBtn addTarget:self action:@selector(termsBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:termsBtn];
    [termsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(emailThread1.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(0);
        make.right.mas_equalTo(self.view).with.offset(0);
        make.height.mas_equalTo(screenScale(49));
    }];
    
    UILabel *termsLabel = [ConfigXp labelWithFrame:CGRectZero
                                              text:@"服务条款"
                                         textColor:getColor(@"4a4a4a")
                                              font:get4sFont(13)
                                     textAlignment:NSTextAlignmentLeft
                                   backgroundColor:[UIColor clearColor]];
    [termsBtn addSubview:termsLabel];
    [termsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(emailThread1.mas_bottom).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(screenScale(15));
        
        make.height.mas_equalTo(screenScale(49));
    }];
    
    UIImageView *termsImg = [[UIImageView alloc]init];
    termsImg.image = [UIImage imageNamed:@"arrow_icon"];
    [self.view addSubview:termsImg];
    [termsImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(termsBtn.mas_centerY);
        
        make.right.mas_equalTo(self.view).with.offset(screenScale(-15));
        
    }];
    
    ///
    
    UIView *bottomView = [[UIView alloc]init];
    bottomView.backgroundColor = getColor(@"f5f5f5");
    [self.view addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view).with.offset(0);
        make.left.mas_equalTo(self.view).with.offset(0);
        make.right.mas_equalTo(self.view).with.offset(0);
        make.top.mas_equalTo(termsLabel.mas_bottom).with.offset(0);
    }];
    
    UILabel *companyLabel = [ConfigXp labelWithFrame:CGRectZero
                                                text:@"天边彩虹公司版权所有"
                                           textColor:getColor(@"9b9b9b")
                                                font:get4sFont(10)
                                       textAlignment:NSTextAlignmentCenter
                                     backgroundColor:[UIColor clearColor]];
    [self.view addSubview:companyLabel];
    [companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bottomView).with.offset(screenScale(25));
        make.left.mas_equalTo(self.view).with.offset(0);
        make.right.mas_equalTo(self.view).with.offset(0);
        
    }];
    
    UILabel *companyLabel1 = [ConfigXp labelWithFrame:CGRectZero
                                                text:@"Copyright@2017-2020ShenyangQuyum"
                                           textColor:getColor(@"9b9b9b")
                                                font:get4sFont(10)
                                       textAlignment:NSTextAlignmentCenter
                                     backgroundColor:[UIColor clearColor]];
    [self.view addSubview:companyLabel1];
    [companyLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bottomView).with.offset(screenScale(42));
        make.left.mas_equalTo(self.view).with.offset(0);
        make.right.mas_equalTo(self.view).with.offset(0);
        
    }];
}

#pragma mark ------------------ click -------------------

- (void)forgetBtnClick{

    NSLog(@"1");
    
//    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_numberLabel.text];
//    UIWebView *callWebview = [[UIWebView alloc] init];
//    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
//    [self.view addSubview:callWebview];

    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_numberLabel.text];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
}

- (void)emailBtnClick{

    NSLog(@"2");
}

- (void)termsBtnClick{

    NSLog(@"3");
    
    getTermsOfServiceViewController *vc = [[getTermsOfServiceViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

@end
